﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using BLL;
using DAL;
using Models;
using System.Data;
using System.Text;
using System.Xml;
using Web.Old_App_Code;

public partial class backstage_left : System.Web.UI.Page
{
    // Fields
    protected AdminGroupManager agm = new AdminGroupManager();
    protected MenuManager mm = new MenuManager();

    // Methods
    protected void btnExit_Click(object sender, EventArgs e)
    {
        this.Session.Remove("admin_user");
        this.Session.Remove("language_version");
        base.ClientScript.RegisterStartupScript(base.GetType(), "", "top.location=\"login.html\";", true);
    }

    protected StringBuilder initializeBind()
    {
        StringBuilder builder = new StringBuilder();
        try
        {
            if ((this.Session["admin_user"] != null) && ((this.Session["admin_user"] as Admin).GroupId == 1))
            {
                builder.AppendLine("<input id=\"btnInitialize\" type=\"button\" value=\"初始化网站\" class=\"formButton\" onclick=\"if(confirm('初始化网站将导致网站数据不可恢复，确定要继续吗？')){top.location='initialize.ashx';}\" />");
            }
        }
        catch
        {
        }
        return builder;
    }

    public StringBuilder MenuBind()
    {
        StringBuilder builder = new StringBuilder();
        try
        {
            DataTable menuByParentMenu = this.mm.GetMenuByParentMenu(0);
            foreach (DataRow row in menuByParentMenu.Rows)
            {
                DataTable menuByAdminGroupAndParentMenu;
                Admin admin = this.Session["admin_user"] as Admin;
                DataTable adminGroupById = this.agm.GetAdminGroupById(admin.GroupId);
                ArrayList list = new ArrayList();
                list.Add(13);
                list.Add(14);
                list.Add(15);
                list.Add(0x13);
                list.Add(0x16);
                list.Add(0x17);
                list.Add(0x18);
                list.Add(0x1b);
                list.Add(0x1c);
                list.Add(0x24);
                list.Add(0x27);
                list.Add(0x2f);
                list.Add(50);
                list.Add(0x34);
                if (Convert.ToInt32(adminGroupById.Rows[0]["isSupplier"]) == 1)
                {
                    if (Convert.ToInt32(row["id"]) == 1)
                    {
                        menuByAdminGroupAndParentMenu = this.mm.GetMenuByParentMenu(Convert.ToInt32(row["id"]));
                        builder.AppendLine("<h1 class=\"type\">");
                        builder.AppendLine("<a href=\"javascript:void(0)\">" + row["menuName"].ToString() + "</a></h1>");
                        builder.AppendLine("<div class=\"content\">");
                        builder.AppendLine("<div>");
                        builder.AppendLine("<img src=\"images/menu_topline.gif\" width=\"182\" height=\"5\" /></div>");
                        builder.AppendLine("<ul class=\"MM\">");
                        foreach (DataRow row2 in menuByAdminGroupAndParentMenu.Rows)
                        {
                            //if (list.Contains(Convert.ToInt32(row2["id"])))
                            //{
                            //    builder.AppendLine("<li><a href=\"javascript:void(0)\" onclick=\"alert('体验版此功能未开通！');\" target=\"main\">" + row2["menuName"].ToString() + "</a></li>");
                            //}
                            //else 
                            if (Convert.ToInt32(row2["id"]) == 10)
                            {
                                builder.AppendLine("<li><a href=\"" + row2["menuUrl"].ToString() + "\" target=\"main\">" + row2["menuName"].ToString() + "</a></li>");
                            }
                        }
                        builder.AppendLine("</ul>");
                        builder.AppendLine("</div>");
                    }
                    if (Convert.ToInt32(row["id"]) == 3)
                    {
                        menuByAdminGroupAndParentMenu = this.mm.GetMenuByParentMenu(Convert.ToInt32(row["id"]));
                        builder.AppendLine("<h1 class=\"type\">");
                        builder.AppendLine("<a href=\"javascript:void(0)\">" + row["menuName"].ToString() + "</a></h1>");
                        builder.AppendLine("<div class=\"content\">");
                        builder.AppendLine("<div>");
                        builder.AppendLine("<img src=\"images/menu_topline.gif\" width=\"182\" height=\"5\" /></div>");
                        builder.AppendLine("<ul class=\"MM\">");
                        foreach (DataRow row2 in menuByAdminGroupAndParentMenu.Rows)
                        {
                            //if (list.Contains(Convert.ToInt32(row2["id"])))
                            //{
                            //    builder.AppendLine("<li><a href=\"javascript:void(0)\" onclick=\"alert('体验版此功能未开通！');\" target=\"main\">" + row2["menuName"].ToString() + "</a></li>");
                            //}
                            //else 
                                if (Convert.ToInt32(row2["id"]) == 0x17)
                            {
                                builder.AppendLine("<li><a href=\"" + row2["menuUrl"].ToString() + "\" target=\"main\">" + row2["menuName"].ToString() + "</a></li>");
                            }
                        }
                        builder.AppendLine("</ul>");
                        builder.AppendLine("</div>");
                    }
                }
                else
                {
                    menuByAdminGroupAndParentMenu = this.mm.GetMenuByAdminGroupAndParentMenu(admin.GroupId, Convert.ToInt32(row["id"]));
                    if (menuByAdminGroupAndParentMenu.Rows.Count > 0)
                    {
                        builder.AppendLine("<h1 class=\"type\">");
                        builder.AppendLine("<a href=\"javascript:void(0)\">" + row["menuName"].ToString() + "</a></h1>");
                        builder.AppendLine("<div class=\"content\">");
                        builder.AppendLine("<div>");
                        builder.AppendLine("<img src=\"images/menu_topline.gif\" width=\"182\" height=\"5\" /></div>");
                        builder.AppendLine("<ul class=\"MM\">");
                        foreach (DataRow row2 in menuByAdminGroupAndParentMenu.Rows)
                        {
                            //if (list.Contains(Convert.ToInt32(row2["id"])))
                            //{
                            //    builder.AppendLine("<li><a href=\"javascript:void(0)\" onclick=\"alert('体验版此功能未开通！');\" target=\"main\">" + row2["menuName"].ToString() + "</a></li>");
                            //}
                            //else
                            //{
                                builder.AppendLine("<li><a href=\"" + row2["menuUrl"].ToString() + "\" target=\"main\">" + row2["menuName"].ToString() + "</a></li>");
                          //  }
                        }
                        builder.AppendLine("</ul>");
                        builder.AppendLine("</div>");
                    }
                }
            }
        }
        catch
        {
        }
        return builder;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if ((HttpContext.Current.Session["admin_user"] == null) && (HttpContext.Current.Session["language_version"] == null))
        {
            base.ClientScript.RegisterStartupScript(base.GetType(), "sJs", "top.location=\"login.html\";", true);
        }
    }

}